//创建报备客户客户
function addReportedCustomer() {
	controllerWaiting(true);
	//获取项目上下文路径
	rootPath = $('#rootPath').val();
	var cusId=$("#cusId").val();
	
	var phone = $('#phone').val();
	var email = $('#email').val();
	var cname = $('#cname').val();
	var remark = $('#remark').val();
	var customerType = $('#customerType').val();
	var url = rootPath + "/customerManage/addReportedCustomer";

	if(phone == "" || email == "") {
		alert("手机跟邮箱不能为空！");
		controllerWaiting(false);
		return ;
	}
	
	//校验手机号和邮箱
	var re = /^1\d{10}$/;
	var re2 = /^0\d{2,3}-?\d{7,8}$/;	
	if (!re.test(phone) && !re2.test(phone)) {
        alert("请输入正确的手机号码");
        controllerWaiting(false);
        return;
    } 
	
	var re3 = /^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/;
	if (!re3.test(email)) {
        alert("请输入正确邮箱地址");
        controllerWaiting(false);
        return;
    } 
	
	var reg = /[<>]/;
	if(reg.test(remark)) {
		alert("你想干嘛?");
		return ;
	}
	if(!checkForm()) {
		return ;
	}
	
	$.post(
		url,
		{
			"cusId": cusId,
			"phone": phone,
			"email": email,
			"cname": cname,
			"remark": remark,
			"customerType": customerType,
		},
		function(data) {
			if(1 == data) {
				alert("创建完成");
				location.href = rootPath + "/page/goReportedCustomer";
				controllerWaiting(false);
			}else if(0 == data) {
				alert('已达可报备客户数量上限！');
				controllerWaiting(false);
				location.href = rootPath + "/page/goReportedCustomer";
			}else if(data==3) {
				alert("用户已存在，并且已存在多条");
				controllerWaiting(false);
			} else {
				alert("用户已存在，会员ID为：" + data);
				controllerWaiting(false);
			}
		}
	);
}




